#! /usr/bin/perl
my @hex= (qw(0 1 2 3 4 5 6 7 8 9 A B C D E F));
my $size = 0;
binmode STDIN;
while (<>) {
  if (/4p-(bytecode|gunzip)/) {
    $_ .= join('', <>);
  } else {
    next if /^\s*[|\\]\s/ || /^\s*$/
          || /^\s*((purpose)|(license)|(copyright)|(status)):\s/;
  }
  if (/^\s*include\s+(\S+)\s*$/) {
    print STDERR "$1\n";
    my $add = `perl $0 <$1`;
    $add =~ s/#define SIZE (\d+)\n$//;
    $size += $1;
    print $add;
  } else {
    s/^\s+//;
    s/\s+$//;
    if (! /L"/ && ! /4p-(bytecode|gunzip)/) {
      s/\s+/ /g;
      s/\r?\n//s;
    }
    $size += length($_) + 1;
    s/(["\\])/\\$1/g;
    my $out = "";
    for (split('')) {
      if (ord($_) < 32 || ord($_) > 126) {
        $out =~ s/""$//;
        $out .= "\\x".$hex[ord($_)/16].$hex[ord($_)%16]."\"\"";
      } else {
        $out =~ s/""$// if !/[0-9a-fA-F]/;
        $out .= $_;
      }
    }
    $out =~ s/""$//;
    print "  \"$out\\x0A\"\n";
  }
}
print "#define SIZE $size\n";
